<template>
    <div class="common_page">
        <a-pagination showSizeChanger :pageSizeOptions="['5','10','20','30']" :pageSize.sync="easyPage.size" @change="getData" :total="easyPage.total"
                      v-model="easyPage.current" @showSizeChange="onShowSizeChange"/>
    </div>
</template>

<script>
  export default {
    name: 'common-page',
    props: {
      value: {
        type: Object,
        required: true
      },
    },
    data () {
      return {
        easyPage:{
          current:1,
          size:10,
          total:1
        }
      }
    },
    watch:{
      value:function () {
        this.easyPage.current = this.value.current
        this.easyPage.size = this.value.size
        this.easyPage.total = this.value.total
      },
      'value.total': function () {
        this.onShowSizeChange(1,10)
      }
    },
    methods: {
      getData (page, pageSize) {
        this.easyPage.current = page
        this.easyPage.size = pageSize
        this.$emit('input', this.easyPage)
        this.$emit('change')
      },
      onShowSizeChange(current, size) {
        this.easyPage.current = current
        this.easyPage.size = size
        this.$emit('input', this.easyPage)
        this.$emit('change')
      }
    },
  }
</script>

<style lang="scss">
    .common_page {
        text-align: right;
        padding: 20px;
    }
</style>